@@ -0,0 +1,23 @@ |
||
1 |
+# Generated by Django 3.2.6 on 2021-08-16 13:48 |
|
2 |
+ |
|
3 |
+from django.db import migrations, models |
|
4 |
+ |
|
5 |
+ |
|
6 |
+class Migration(migrations.Migration): |
|
7 |
+ |
|
8 |
+ dependencies = [ |
|
9 |
+ ('account', '0003_auto_20210816_1054'), |
|
10 |
+ ] |
|
11 |
+ |
|
12 |
+ operations = [ |
|
13 |
+ migrations.AlterField( |
|
14 |
+ model_name='administratorinfo', |
|
15 |
+ name='status', |
|
16 |
+ field=models.BooleanField(default=True, help_text='Status', verbose_name='status'), |
|
17 |
+ ), |
|
18 |
+ migrations.AlterField( |
|
19 |
+ model_name='userinfo', |
|
20 |
+ name='status', |
|
21 |
+ field=models.BooleanField(default=True, help_text='Status', verbose_name='status'), |
|
22 |
+ ), |
|
23 |
+ ] |
@@ -90,13 +90,13 @@ def eqpt_onoff(request): |
||
90 | 90 |
|
91 | 91 |
if active == 0: |
92 | 92 |
try: |
93 |
- user = IsolationPointUserInfo.objects.get(pk=eqpt.ipui_pk) |
|
93 |
+ ipui = IsolationPointUserInfo.objects.get(pk=eqpt.ipui_pk) |
|
94 | 94 |
except IsolationPointUserInfo.DoesNotExist: |
95 |
- user = None |
|
96 |
- if user: |
|
97 |
- user.leave_at = tc.utc_datetime() |
|
98 |
- user.status = False |
|
99 |
- user.save() |
|
95 |
+ ipui = None |
|
96 |
+ if ipui: |
|
97 |
+ ipui.leave_at = tc.utc_datetime() |
|
98 |
+ ipui.status = False |
|
99 |
+ ipui.save() |
|
100 | 100 |
|
101 | 101 |
return response() |
102 | 102 |
|
@@ -116,12 +116,12 @@ def eqpt_remark(request): |
||
116 | 116 |
|
117 | 117 |
# 存放历史备注记录 |
118 | 118 |
try: |
119 |
- user = IsolationPointUserInfo.objects.get(pk=eqpt.ipui_pk) |
|
119 |
+ ipui = IsolationPointUserInfo.objects.get(pk=eqpt.ipui_pk) |
|
120 | 120 |
except IsolationPointUserInfo.DoesNotExist: |
121 |
- user = None |
|
122 |
- if user: |
|
123 |
- user.remark += [remark] |
|
124 |
- user.save() |
|
121 |
+ ipui = None |
|
122 |
+ if ipui: |
|
123 |
+ ipui.remark += [remark] |
|
124 |
+ ipui.save() |
|
125 | 125 |
|
126 | 126 |
return response() |
127 | 127 |
|
@@ -176,8 +176,8 @@ def eqpt_result(request): |
||
176 | 176 |
).values('macid', 'temperature') |
177 | 177 |
logs = {log.get('macid'): log.get('temperature') for log in logs} |
178 | 178 |
|
179 |
- infos = IsolationPointUserInfo.objects.filter(point_id=point_id, status=True).values('pk', 'fields') |
|
180 |
- infos = {info.get('pk'): info.get('fields') for info in infos} |
|
179 |
+ ipuis = IsolationPointUserInfo.objects.filter(point_id=point_id, status=True).values('pk', 'fields') |
|
180 |
+ ipuis = {info.get('pk'): info.get('fields') for info in ipuis} |
|
181 | 181 |
|
182 | 182 |
total_active_eqpt_num = eqpts.count() |
183 | 183 |
has_upload_temperature_num = len(logs) |
@@ -189,7 +189,7 @@ def eqpt_result(request): |
||
189 | 189 |
eqpts = [{**eqpt.data, **{ |
190 | 190 |
'has_upload': eqpt.macid in logs, |
191 | 191 |
'temperature': logs.get(eqpt.macid, 0), |
192 |
- 'fields': infos.get(eqpt.ipui_pk, {}), |
|
192 |
+ 'fields': ipuis.get(eqpt.ipui_pk, {}), |
|
193 | 193 |
}} for eqpt in eqpts] |
194 | 194 |
|
195 | 195 |
return response(data={ |
@@ -221,8 +221,8 @@ def get_screen_data(point=None, point_id=None): |
||
221 | 221 |
).values('macid', 'temperature') |
222 | 222 |
logs = {log.get('macid'): log.get('temperature') or get_old_temperature(point.point_id, log.get('macid')) for log in logs} |
223 | 223 |
|
224 |
- infos = IsolationPointUserInfo.objects.filter(point_id=point.point_id, status=True).values('pk', 'fields') |
|
225 |
- infos = {info.get('pk'): info.get('fields') for info in infos} |
|
224 |
+ ipuis = IsolationPointUserInfo.objects.filter(point_id=point.point_id, status=True).values('pk', 'fields', 'observed_days') |
|
225 |
+ ipuis = {info.get('pk'): {'fields': info.get('fields'), 'observed_days': info.get('observed_days')} for info in ipuis} |
|
226 | 226 |
|
227 | 227 |
total_active_eqpt_num = eqpts.count() |
228 | 228 |
has_upload_temperature_num = len(logs) |
@@ -231,7 +231,8 @@ def get_screen_data(point=None, point_id=None): |
||
231 | 231 |
eqpts = [{**eqpt.screen_data, **{ |
232 | 232 |
'has_upload': eqpt.macid in logs, |
233 | 233 |
'temperature': logs.get(eqpt.macid, 0), |
234 |
- }, **{field.get('key', ''): field.get('value', '') for field in infos.get(eqpt.ipui_pk, {})}} for eqpt in eqpts] |
|
234 |
+ 'observed_days': ipuis.get(eqpt.ipui_pk, {}).get('observed_days', 0), |
|
235 |
+ }, **{field.get('key', ''): field.get('value', '') for field in ipuis.get(eqpt.ipui_pk, {}).get('fields', {})}} for eqpt in eqpts] |
|
235 | 236 |
reminds = [{ |
236 | 237 |
'name': eqpt.get('name'), |
237 | 238 |
'room': eqpt.get('room'), |
@@ -257,7 +258,7 @@ def get_screen_data(point=None, point_id=None): |
||
257 | 258 |
'temperature': eqpt.get('temperature', ''), |
258 | 259 |
'status': '已上报' if eqpt.get('temperature') else '未上报', |
259 | 260 |
'last_report_time': eqpt.get('last_submit_at', ''), |
260 |
- 'observed_days': 1, |
|
261 |
+ 'observed_days': eqpt.get('observed_days', 0), |
|
261 | 262 |
} for eqpt in eqpts] |
262 | 263 |
|
263 | 264 |
return { |
@@ -405,4 +406,13 @@ def mqtt_upload_temperature(payload): |
||
405 | 406 |
|
406 | 407 |
set_old_temperature(eqpt.point_id, macid, temperature) |
407 | 408 |
|
409 |
+ try: |
|
410 |
+ ipui = IsolationPointUserInfo.objects.get(pk=eqpt.ipui_pk) |
|
411 |
+ except IsolationPointUserInfo.DoesNotExist: |
|
412 |
+ ipui = None |
|
413 |
+ if ipui: |
|
414 |
+ ipui.observed_ymds = list(set(ipui.observed_ymds + [point_measure_ymd])) |
|
415 |
+ ipui.observed_days = len(ipui.observed_ymds) |
|
416 |
+ ipui.save() |
|
417 |
+ |
|
408 | 418 |
set_screen_info(point.point_id, get_screen_data(point)) |
@@ -16,7 +16,7 @@ class IsolationPointInfoAdmin(admin.ModelAdmin): |
||
16 | 16 |
|
17 | 17 |
|
18 | 18 |
class IsolationPointUserInfoAdmin(admin.ModelAdmin): |
19 |
- list_display = ('point_id', 'user_id', 'fields', 'status', 'updated_at', 'created_at') |
|
19 |
+ list_display = ('point_id', 'user_id', 'fields', 'observed_days', 'leave_at', 'status', 'updated_at', 'created_at') |
|
20 | 20 |
|
21 | 21 |
|
22 | 22 |
class ThermometerEquipmentInfoAdmin(ReadOnlyModelAdmin, admin.ModelAdmin): |
@@ -0,0 +1,48 @@ |
||
1 |
+# Generated by Django 3.2.6 on 2021-08-16 13:48 |
|
2 |
+ |
|
3 |
+from django.db import migrations, models |
|
4 |
+ |
|
5 |
+ |
|
6 |
+class Migration(migrations.Migration): |
|
7 |
+ |
|
8 |
+ dependencies = [ |
|
9 |
+ ('equipment', '0009_auto_20210816_1054'), |
|
10 |
+ ] |
|
11 |
+ |
|
12 |
+ operations = [ |
|
13 |
+ migrations.AddField( |
|
14 |
+ model_name='isolationpointuserinfo', |
|
15 |
+ name='observed_days', |
|
16 |
+ field=models.IntegerField(default=0, help_text='已测温天数', verbose_name='observed_days'), |
|
17 |
+ ), |
|
18 |
+ migrations.AlterField( |
|
19 |
+ model_name='isolationpointfieldpoolinfo', |
|
20 |
+ name='status', |
|
21 |
+ field=models.BooleanField(default=True, help_text='Status', verbose_name='status'), |
|
22 |
+ ), |
|
23 |
+ migrations.AlterField( |
|
24 |
+ model_name='isolationpointinfo', |
|
25 |
+ name='status', |
|
26 |
+ field=models.BooleanField(default=True, help_text='Status', verbose_name='status'), |
|
27 |
+ ), |
|
28 |
+ migrations.AlterField( |
|
29 |
+ model_name='isolationpointuserinfo', |
|
30 |
+ name='status', |
|
31 |
+ field=models.BooleanField(default=True, help_text='Status', verbose_name='status'), |
|
32 |
+ ), |
|
33 |
+ migrations.AlterField( |
|
34 |
+ model_name='thermometerequipmentinfo', |
|
35 |
+ name='status', |
|
36 |
+ field=models.BooleanField(default=True, help_text='Status', verbose_name='status'), |
|
37 |
+ ), |
|
38 |
+ migrations.AlterField( |
|
39 |
+ model_name='thermometermeasureinfo', |
|
40 |
+ name='status', |
|
41 |
+ field=models.BooleanField(default=True, help_text='Status', verbose_name='status'), |
|
42 |
+ ), |
|
43 |
+ migrations.AlterField( |
|
44 |
+ model_name='thermometermeasureloginfo', |
|
45 |
+ name='status', |
|
46 |
+ field=models.BooleanField(default=True, help_text='Status', verbose_name='status'), |
|
47 |
+ ), |
|
48 |
+ ] |
@@ -0,0 +1,19 @@ |
||
1 |
+# Generated by Django 3.2.6 on 2021-08-16 13:57 |
|
2 |
+ |
|
3 |
+from django.db import migrations |
|
4 |
+import jsonfield.fields |
|
5 |
+ |
|
6 |
+ |
|
7 |
+class Migration(migrations.Migration): |
|
8 |
+ |
|
9 |
+ dependencies = [ |
|
10 |
+ ('equipment', '0010_auto_20210816_2148'), |
|
11 |
+ ] |
|
12 |
+ |
|
13 |
+ operations = [ |
|
14 |
+ migrations.AddField( |
|
15 |
+ model_name='isolationpointuserinfo', |
|
16 |
+ name='observed_ymds', |
|
17 |
+ field=jsonfield.fields.JSONField(blank=True, default=[], help_text='已测温日期', null=True, verbose_name='observed_ymds'), |
|
18 |
+ ), |
|
19 |
+ ] |
@@ -142,7 +142,9 @@ class IsolationPointUserInfo(BaseModelMixin): |
||
142 | 142 |
|
143 | 143 |
fields = JSONField(_('fields'), default=[], blank=True, null=True, help_text='字段信息') |
144 | 144 |
|
145 |
- leave_at = models.DateTimeField(_('leave_at'), blank=True, null=True, help_text=_('离开时间')) |
|
145 |
+ observed_ymds = JSONField(_('observed_ymds'), default=[], blank=True, null=True, help_text='已测温日期') |
|
146 |
+ observed_days = models.IntegerField(_('observed_days'), default=0, help_text='已测温天数') |
|
147 |
+ leave_at = models.DateTimeField(_('leave_at'), blank=True, null=True, help_text='离开时间') |
|
146 | 148 |
|
147 | 149 |
remark = JSONField(_('remark'), default=[], blank=True, null=True, help_text='备注') |
148 | 150 |
|
@@ -191,7 +193,7 @@ class ThermometerEquipmentInfo(BaseModelMixin): |
||
191 | 193 |
sn = models.CharField(_('sn'), max_length=32, blank=True, null=True, help_text='序列号') |
192 | 194 |
|
193 | 195 |
active_status = models.IntegerField(_('active_status'), choices=ACTIVE_STATUE_TUPLE, default=OFFLINE, help_text='激活状态') |
194 |
- active_at = models.DateTimeField(_('active_at'), blank=True, null=True, help_text=_('激活时间')) |
|
196 |
+ active_at = models.DateTimeField(_('active_at'), blank=True, null=True, help_text='激活时间') |
|
195 | 197 |
|
196 | 198 |
# 用户基本信息 |
197 | 199 |
ipui_pk = models.IntegerField(_('ipui_pk'), default=0, help_text='隔离点用户录入PK') |
@@ -204,7 +206,7 @@ class ThermometerEquipmentInfo(BaseModelMixin): |
||
204 | 206 |
|
205 | 207 |
remark = models.CharField(_('remark'), max_length=255, blank=True, null=True, help_text='备注') |
206 | 208 |
|
207 |
- last_submit_at = models.DateTimeField(_('last_submit_at'), blank=True, null=True, help_text=_('上一次上报时间')) |
|
209 |
+ last_submit_at = models.DateTimeField(_('last_submit_at'), blank=True, null=True, help_text='上一次上报时间') |
|
208 | 210 |
|
209 | 211 |
eqpt_register_status = models.IntegerField(_('eqpt_register_status'), choices=REGISTER_STATUE_TUPLE, default=FAIL, help_text='设备注册状态') |
210 | 212 |
eqpt_register_result = models.TextField(_('eqpt_register_result'), blank=True, null=True, help_text='设备注册结果') |
@@ -5,9 +5,9 @@ from django.utils.translation import ugettext_lazy as _ |
||
5 | 5 |
|
6 | 6 |
|
7 | 7 |
class BaseModelMixin(models.Model): |
8 |
- status = models.BooleanField(_('status'), default=True, help_text=_('状态'), db_index=True) |
|
9 |
- created_at = models.DateTimeField(_('created_at'), auto_now_add=True, editable=True, help_text=_('创建时间')) |
|
10 |
- updated_at = models.DateTimeField(_('updated_at'), auto_now=True, editable=True, help_text=_('更新时间')) |
|
8 |
+ status = models.BooleanField(_('status'), default=True, help_text='状态', db_index=True) |
|
9 |
+ created_at = models.DateTimeField(_('created_at'), auto_now_add=True, editable=True, help_text='创建时间') |
|
10 |
+ updated_at = models.DateTimeField(_('updated_at'), auto_now=True, editable=True, help_text='更新时间') |
|
11 | 11 |
|
12 | 12 |
class Meta: |
13 | 13 |
abstract = True |